package com.spic.business.ioc.service.impl;

import com.spic.business.ioc.domain.IocDustConcentration;
import com.spic.business.ioc.mapper.IocDustConcentrationMapper;
import com.spic.business.ioc.service.IIocDustConcentrationService;
import com.spic.common.core.domain.R;
import com.spic.common.core.utils.StringUtils;
import com.spic.common.core.utils.UUIDUtil;
import com.spic.system.api.RemoteDictDataService;
import com.spic.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 粉尘浓度数据IOCService业务层处理
 *
 * @author spic
 * @date 2022-04-14
 */
@Service
public class IocDustConcentrationServiceImpl implements IIocDustConcentrationService
{
    @Autowired
    private IocDustConcentrationMapper iocDustConcentrationMapper;

    @Autowired
    private RemoteDictDataService remoteDictDataService;
    /**
     * 查询粉尘浓度数据IOC
     *
     * @param id 粉尘浓度数据IOC主键
     * @return 粉尘浓度数据IOC
     */
    @Override
    public IocDustConcentration selectIocDustConcentrationById(String id)
    {
        return iocDustConcentrationMapper.selectIocDustConcentrationById(id);
    }

    /**
     * 查询粉尘浓度数据IOC列表
     *
     * @param iocDustConcentration 粉尘浓度数据IOC
     * @return 粉尘浓度数据IOC
     */
    @Override
    public List<IocDustConcentration> selectIocDustConcentrationList(IocDustConcentration iocDustConcentration)
    {
        return iocDustConcentrationMapper.selectIocDustConcentrationList(iocDustConcentration);
    }

    /**
     * 新增粉尘浓度数据IOC
     *
     * @param iocDustConcentration 粉尘浓度数据IOC
     * @return 结果
     */
    @Override
    public int insertIocDustConcentration(IocDustConcentration iocDustConcentration)
    {
        if(StringUtils.isNotEmpty(iocDustConcentration.getMonitoringLocation()))
        {
            R<List<SysDictData>> monitoring_location_type = remoteDictDataService.getDictDataByDictType("monitoring_location_type");
            List<SysDictData> dictList = monitoring_location_type.getData();

            for (SysDictData dict : dictList)
            {
                //分类列表数据
                if (dict.getDictValue().equals(iocDustConcentration.getMonitoringLocation()))
                {
                    iocDustConcentration.setMonitoringLocationName(dict.getDictLabel());
                    break;
                }
            }
        }
        String uuid = UUIDUtil.createUUID();
        iocDustConcentration.setId(uuid);
        return iocDustConcentrationMapper.insertIocDustConcentration(iocDustConcentration);
    }

    /**
     * 修改粉尘浓度数据IOC
     *
     * @param iocDustConcentration 粉尘浓度数据IOC
     * @return 结果
     */
    @Override
    public int updateIocDustConcentration(IocDustConcentration iocDustConcentration)
    {
        if(StringUtils.isNotEmpty(iocDustConcentration.getMonitoringLocation())) {
            R<List<SysDictData>> monitoring_location_type = remoteDictDataService.getDictDataByDictType("monitoring_location_type");
            List<SysDictData> dictList = monitoring_location_type.getData();

            for (SysDictData dict : dictList)
            {
                //分类列表数据
                if (dict.getDictValue().equals(iocDustConcentration.getMonitoringLocation()))
                {
                    iocDustConcentration.setMonitoringLocationName(dict.getDictLabel());
                    break;
                }
            }
        }
        return iocDustConcentrationMapper.updateIocDustConcentration(iocDustConcentration);
    }

    /**
     * 批量删除粉尘浓度数据IOC
     *
     * @param ids 需要删除的粉尘浓度数据IOC主键
     * @return 结果
     */
    @Override
    public int deleteIocDustConcentrationByIds(String[] ids)
    {
        return iocDustConcentrationMapper.deleteIocDustConcentrationByIds(ids);
    }

    /**
     * 删除粉尘浓度数据IOC信息
     *
     * @param id 粉尘浓度数据IOC主键
     * @return 结果
     */
    @Override
    public int deleteIocDustConcentrationById(String id)
    {
        return iocDustConcentrationMapper.deleteIocDustConcentrationById(id);
    }

    /**
     * @return 粉尘浓度数据
     */

    @Override
    public List<Map<String, Object>> getDustConcentration()
    {
        return null;
    }
}
